# 通讯录小程序
def viewList():
    welcome = '|---欢迎进入通讯录程序---|'
    select = '|---1：查询联系人资料---|'
    insert = '|---2：插入新的联系人---|'
    delete = '|---3：删除已有联系人---|'
    viewdict = '|---4：显示所有通讯录人员---|'
    quitphone = '|---5：退出通讯录程序---|'
    list1 = [welcome, select, insert, delete, viewdict,quitphone]
    for i in list1:
        print(i)

dictphon = {'dengjiaming':'13391866288'}   

def judgeDictName():
    contactName = input('请输入联系人姓名:')
    if contactName in dictphon.keys():
        return contactName
    else:
        print('通讯录中没有此联系人')
        return 'no'

def queryContact():
    contactName = judgeDictName()
    if contactName != 'no':
        print('查询的姓名是：'+contactName)
        print('联系电话是：'+ dictphon[contactName])

def insertContact():
    def addPhoneCode():
        telephoneCode=input('请输入用户联系电话：')
        dictphon[contactName]=telephoneCode
    contactName = input('请输入联系人姓名:')
    if contactName in dictphon.keys():
        print('您输入的姓名在通讯录中已存在-->>'+contactName+':'+dictphon[contactName])
        modify=input('是否修改用户资料（YES/NO）：')
        if modify=='YES':
            addPhoneCode()
    else:
        addPhoneCode()

def deleteContact():
    contactName = judgeDictName()
    if contactName!='no':
        dictphon.pop(contactName)

def viewDictWhole():
    print('所有的联系人有')
    print(dictphon.items())
        
while 1:
    viewList()
    enterCode = input('请输入相关指令代码:')
    if enterCode=='1':
        queryContact()
    elif enterCode=='2':
        insertContact()
    elif enterCode=='3':
        deleteContact()
    elif enterCode=='4':
        viewDictWhole()
    elif enterCode=='5':
        print('已经正常退出程序了')
        break
    else:
        print('输入1-5傻逼：')
